输入一整数S(0<=s<=32767)若不在范围内重新输入要求从个位数开始分离每位占一行

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:35:31
用C++编程

vc

#include <iostream.h>
void fun(int);
void main(){
int a;
cout<<"输入一整数S(0<=s<=32767)"<<endl;
cin>>a;
fun(a);
while (a<0||a>32767){
cout<<"请重新输入"<<endl;
cin>>a;
fun(a);
}

return;
}

void fun (int s){
if (s>=0&&s<=32767){
if (s>=10000){
cout<<s%10<<endl;
cout<<s%100/10<<endl;
cout<<s%1000/100<<endl;
cout<<s%10000/1000<<endl;
cout<<s/10000<<endl;
return;
}

if (s>=1000){
cout<<s%10<<endl;
cout<<s%100/10<<endl;
cout<<s%1000/100<<endl;
cout<<s/1000<<endl;
return;
}

if (s>=100){
cout<<s%10<<endl;
cout<<s%100/10<&l